From 989d974459f1c1ecab7053caf9d9ab5abb89f6b9 Mon Sep 17 00:00:00 2001 From: Anton Gladky Date: Fri, 28 Aug 2026 08:57:41 +0000 Subject: [PATCH] Fix segfault writing ascii .vtu files with implicit cell type arrays Forwarded: not-yet NewIterator() returns nullptr for the implicit cell-type arrays used since VTK 9.6, so WriteAsciiData() dereferenced that nullptr in iter->Delete(). Merely guarding the Delete() is not enough: the templated writer already returns early on a null iterator, so the array is then written empty, and since WriteInlineData() discards the return value the writer reports success for a file which has lost all of its cells. Write such arrays through an explicit copy instead. Closes yade FTBFS. Gbp-Pq: Name fix_xmlwriter_ascii_implicit_cellarray_segfault.patch --- IO/XML/vtkXMLWriter.cxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/IO/XML/vtkXMLWriter.cxx b/IO/XML/vtkXMLWriter.cxx index 413f0f885..c56e26416 100644 --- a/IO/XML/vtkXMLWriter.cxx +++ b/IO/XML/vtkXMLWriter.cxx @@ -34,6 +34,7 @@ #include "vtkOutputStream.h" #include "vtkPointData.h" #include "vtkPoints.h" +#include "vtkSmartPointer.h" #include "vtkStdString.h" #include "vtkStreamingDemandDrivenPipeline.h" #include "vtkStringFormatter.h" @@ -1968,6 +1969,15 @@ int vtkXMLWriteAsciiData(ostream& os, iterT* iter, vtkIndent indent) int vtkXMLWriter::WriteAsciiData(vtkAbstractArray* a, vtkIndent indent) { vtkArrayIterator* iter = a->NewIterator(); + vtkSmartPointer copy; + if (!iter) + { + // Arrays which provide no iterator, such as the implicit arrays used since VTK 9.6 + // for uniform cell types, are written through an explicit copy. + copy.TakeReference(vtkAbstractArray::CreateArray(a->GetDataType())); + copy->DeepCopy(a); + iter = copy->NewIterator(); + } ostream& os = *(this->Stream); int ret; switch (a->GetDataType()) @@ -1978,7 +1988,10 @@ int vtkXMLWriter::WriteAsciiData(vtkAbstractArray* a, vtkIndent indent) ret = 0; break; } - iter->Delete(); + if (iter) + { + iter->Delete(); + } return ret; } -- 2.30.2